package com.phpxiu.app.view.dialog;

import android.app.Dialog;
import android.content.Context;
import android.view.View;
import android.widget.Button;

import com.phpxiu.app.api.listener.OnUserManageWinListener;
import com.phpxiu.app.config.Constants;
import com.phpxiu.app.kkylive.R;
import com.phpxiu.app.model.MySelfInfo;

import java.lang.ref.WeakReference;

/**
 * 房间管理菜单窗口
 * Created by WuJinZhou on 2016/5/27.
 */
public class RoomManageMenus extends Dialog implements View.OnClickListener {
    private View hostMenus,adminMenus;
    private Button adminOperaBtn;
    private WeakReference<OnUserManageWinListener>weakListener;
    public RoomManageMenus(Context context) {
        super(context,R.style.menusDialog);
        setContentView(R.layout.main_room_manage_menus);
        hostMenus=findViewById(R.id.host_menus);
        adminMenus=findViewById(R.id.admin_menus);
        findViewById(R.id.admin_manage_report).setOnClickListener(this);
        findViewById(R.id.admin_manage_speak).setOnClickListener(this);
        findViewById(R.id.admin_close_btn).setOnClickListener(this);
        adminOperaBtn=(Button)findViewById(R.id.host_manage_admin);
        adminOperaBtn.setOnClickListener(this);
        findViewById(R.id.host_manage_admin_list).setOnClickListener(this);
        findViewById(R.id.host_manage_speak).setOnClickListener(this);
        findViewById(R.id.host_close_btn).setOnClickListener(this);
        findViewById(R.id.base_view).setOnClickListener(this);
    }

    /**
     * 显示菜单
     * @param cancelAdmin 是否取消管理员
     */
    public void show(boolean cancelAdmin) {
        if(MySelfInfo.getInstance().getIdStatus()== Constants.HOST){
            adminOperaBtn.setText(cancelAdmin==true?getContext().getString(R.string.ui_room_menus_admin_):getContext().getString(R.string.ui_room_menus_admin));
            //主播管理
            if(adminMenus.getVisibility()==View.VISIBLE){
                adminMenus.setVisibility(View.INVISIBLE);
            }
            if(hostMenus.getVisibility()!=View.VISIBLE){
                hostMenus.setVisibility(View.VISIBLE);
            }
        }else{
            //管理员管理
            if(adminMenus.getVisibility()!=View.VISIBLE){
                adminMenus.setVisibility(View.VISIBLE);
            }
            if(hostMenus.getVisibility()==View.VISIBLE){
                hostMenus.setVisibility(View.INVISIBLE);
            }
        }
        super.show();
    }

    @Override
    public void onClick(View v) {
        switch (v.getId()){
            case R.id.admin_manage_report:
                if(weakListener!=null&&weakListener.get()!=null){
                    weakListener.get().onReport();
                }
                break;
            case R.id.host_manage_admin:
                if(weakListener!=null&&weakListener.get()!=null){
                    weakListener.get().onAdminOpera();
                }
                dismiss();
                break;
            case R.id.host_manage_admin_list:
                if(weakListener!=null&&weakListener.get()!=null){
                    weakListener.get().adminList();
                }
                dismiss();
                break;
            case R.id.host_manage_speak:
            case R.id.admin_manage_speak:
                if(weakListener!=null&&weakListener.get()!=null){
                    weakListener.get().onSpeakOpera();
                }
                dismiss();
                break;
            case R.id.base_view:
            case R.id.admin_close_btn:
            case R.id.host_close_btn:
                dismiss();
                break;
            default:
                break;
        }
    }

    public void addOnUserManageListener(OnUserManageWinListener listener){
        if(listener==null){
            if(weakListener!=null){
                weakListener.clear();
                weakListener=null;
            }
        }else{
            weakListener=new WeakReference<OnUserManageWinListener>(listener);
        }
    }
}
